#include <iostream>
#include <string>
#include <cctype>
#include <iomanip>

using namespace std;

double M[4] = {12.01, 1.008, 16.00, 14.01};
int main() {
    int t;
    cin >> t;
    while(t--){
        string s;
        cin >> s;
        double ans = 0;
        for(size_t i=0; i<s.size();){
            double val = 0;
            switch(s[i]){
                case 'C': val = M[0]; break;
                case 'H': val = M[1]; break;
                case 'O': val = M[2]; break;
                case 'N': val = M[3]; break;
            }
            if(isdigit(s[i+1])){
                if(isdigit(s[i+2])){
                    val *= stoi(s.substr(i+1));
                    i+=2;
                }
                else{
                    val *= stoi(s.substr(i+1));
                    i++;
                }
            }
            else i++;
            ans += val;
        }
        cout << fixed << setprecision(3) << ans << endl;
    }
    return 0;
}